通过阅读本文,您可以了解通过服务端SDK调用OpenAPI发起并查询智能媒体服务截图任务的示例代码。
使用说明
发起截图任务前,需要先创建截图模板。通过TemplateId(截图模板ID)发起截图任务,发起截图任务时,支持对截图模板参数进行覆盖重置,截图任务处理成功后,可以根据返回的JobId(任务ID)查询该截图任务的详细信息、截图任务列表及截图的访问URL。
示例代码
您可以通过阿里云OpenAPI开发者门户在线调试。
<?php
require_once '../vendor/autoload.php';
use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models;
use AlibabaCloud\SDK\ICE\V20201109\Models\ListSnapshotJobsRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetSnapshotUrlsRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetSnapshotJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\CreateCustomTemplateRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitSnapshotJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitSnapshotJobRequest\output;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitSnapshotJobRequest\input;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitSnapshotJobRequest\templateConfig;
use Darabonba\OpenApi\Models\Config;
try {
// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。配置方法请参见:https://help.aliyun.com/document_detail/311677.html
$credential = new Credential([]);
$config = new Config([
'credential' => $credential,
'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
]);
// 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// $config->accessKeyId = '<yourAccessKeyId>';
// $config->accessKeySecret = '<yourAccessKeySecret>';
$client = new ICE($config);
// 创建截图模板
$snapshotTemplateConfig = "{\"Type\":\"Normal\",\"FrameType\":\"normal\",\"Time\":0,\"Count\":10}";
$request = new CreateCustomTemplateRequest();
$request->name = "sdk_sample_snapshot_template";
$request->type = 2;
$request->templateConfig = $snapshotTemplateConfig;
$response = $client->createCustomTemplate($request);
echo json_encode($response->body);
// 发起截图任务
$request = new SubmitSnapshotJobRequest();
$request->name = "sdk_sample_snapshot_job";
$request->input = new input(["type" => "Media","media" => "3945e42d01823498****"]);
$request->output = new output(["type" => "Media","media" => "3945e42d01823498****"]);
$request->templateConfig = new templateConfig(["templateId" => "4945e09631823498****"]);
$response = $client->submitSnapshotJob($request);
echo json_encode($response->body);
// 查询截图任务详细信息
$request = new GetSnapshotJobRequest();
$request->jobId = "20b48fb04483915d4f2cd8ac****";
$response = $client->getSnapshotJob($request);
echo json_encode($response->body);
// 获取截图任务列表
$request = new ListSnapshotJobsRequest();
$request->pageSize = 5;
$response = $client->listSnapshotJobs($request);
echo json_encode($response->body);
// 获取截图任务输出图片的访问URL
$request = new GetSnapshotUrlsRequest();
$request->pageSize = 5;
$request->jobId = "20b48fb04483915d4f2cd8ac****";
$response = $client->getSnapshotUrls($request);
echo json_encode($response->body);
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
}
相关接口
文档内容是否对您有帮助?